package baduga.karo;
import java.awt.Toolkit;

import baduga.core.*;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

//okienko "Raise"

/**
* @author Karolina
*/

public class Raise extends javax.swing.JFrame {

		   
		private static final long serialVersionUID = 1L;
		private JTextField textField;
		
		//zmiana ikonki na pasku tytyłu
		
	    public Raise() {
			setIconImage(Toolkit.getDefaultToolkit().getImage(AboutAuthorsScreen.class.getResource("/baduga/karo/resources/icon.png")));
	        initComponents();
	    }

	    public int raiseAmount(int amount) {
        	return amount;
        }
	    
	    
	    //@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
	    private void initComponents() {

	        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
	        setTitle("Raise");
	        setResizable(false);
	        
	        JLabel lblPodajLiczbetonw = new JLabel("Podaj liczbę żetonów o jaką chcesz zwiększyć zakład");
	        
	        
	        
	        textField = new JTextField();
	        textField.setColumns(10);
	        
	        int aktualnakwota = 500;
	        
	        //obsługa przycisków "ok" i "anuluj"
	        
	        JButton btnOk = new JButton("OK");
	        btnOk.addActionListener(new ActionListener() {
	        	public void actionPerformed(final ActionEvent arg0) {
	        		
	        		int amountCash = 0;
	        		boolean parseState = true;
	        			        			
	        		try {
	        			 amountCash = Integer.parseInt(textField.getText());
	        		}
	        		catch(NumberFormatException ex){
	        			JOptionPane.showMessageDialog(null, "Niepoprawna wartość");
	        			parseState = false;
	        			
	        		}
	        		
	        		if((amountCash <= 0 || amountCash > aktualnakwota) && parseState) {
	        			JOptionPane.showMessageDialog(null, "Niepoprawna wartość");
	        		}
	        		else if(amountCash != 0 && parseState){
	        			dispose();
	        			raiseAmount(amountCash);	        			
	        		}
	        		
	        		
	        	}
	        });
	        
	        
	        JButton btnAnuluj = new JButton("Anuluj");
	        btnAnuluj.addActionListener(new ActionListener() {
	        	public void actionPerformed(ActionEvent arg0) {
	        		dispose();
	        	}
	        });
	        
	        
	      
	        //własności okna
	        
	        final GroupLayout layout = new GroupLayout(getContentPane());
	        layout.setHorizontalGroup(
	        	layout.createParallelGroup(Alignment.LEADING)
	        		.addGroup(layout.createSequentialGroup()
	        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
	        				.addGroup(layout.createSequentialGroup()
	        					.addGap(84)
	        					.addComponent(btnOk, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
	        					.addGap(18)
	        					.addComponent(btnAnuluj))
	        				.addGroup(layout.createSequentialGroup()
	        					.addGap(30)
	        					.addGroup(layout.createParallelGroup(Alignment.LEADING, false)
	        						.addComponent(lblPodajLiczbetonw, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	        						.addComponent(textField, GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE))))
	        			.addContainerGap(40, Short.MAX_VALUE))
	        );
	        layout.setVerticalGroup(
	        	layout.createParallelGroup(Alignment.LEADING)
	        		.addGroup(layout.createSequentialGroup()
	        			.addGap(20)
	        			.addComponent(lblPodajLiczbetonw, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
	        			.addPreferredGap(ComponentPlacement.RELATED)
	        			.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
	        			.addGap(18)
	        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
	        				.addComponent(btnAnuluj)
	        				.addComponent(btnOk))
	        			.addContainerGap(13, Short.MAX_VALUE))
	        );
	        getContentPane().setLayout(layout);

	        pack();
	    }

	  
	    public static void main(String args[]) {
	      
	    	//zmieniamy styl okienek, jeżeli ten będzie niedostępny ładowany jest domyślny
	    	
	        try {
	            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
	                if ("Nimbus".equals(info.getName())) {
	                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
	                    break;
	                }
	            }
	        } catch (ClassNotFoundException ex) {
	            java.util.logging.Logger.getLogger(AboutAuthorsScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        } catch (InstantiationException ex) {
	            java.util.logging.Logger.getLogger(AboutAuthorsScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        } catch (IllegalAccessException ex) {
	            java.util.logging.Logger.getLogger(AboutAuthorsScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
	            java.util.logging.Logger.getLogger(AboutAuthorsScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	        }
	      
	        java.awt.EventQueue.invokeLater(new Runnable() {
	            @Override
	            public void run() {
	            	Raise raiseWindow = new Raise();
	                raiseWindow.setVisible(true);
	                raiseWindow.setLocationRelativeTo(null);
	            }
	        });
	    }
	}


